(function() {
  'use strict';

  angular
    .module('hp')
    .controller('MachineCodeUploadController', MachineCodeUploadController);

  /** @ngInject */
  function MachineCodeUploadController($log,toastr,$scope,$state,$stateParams,UploadCodeService,$rootScope){
      var vm = this;
      vm.upload = upload;
      vm.form={
          code:''
      }
      function upload(){
  			angular.element('#submit').blur();
  			// $rootScope.$broadcast('loading:start','');
  			UploadCodeService.post({},{body:vm.form}).$promise.then(function(data){
  	        // $rootScope.$broadcast('loading:finished','');
            var c = data || {};
            var code = c.head.errorCode + '';
            switch (code) {
                case '200':
                    toastr.info('提交成功')
                    $state.go('machinecode')
                    break;
                case '401':
                case '403':
                    $rootScope.$broadcast('event:auth-require',{});
                    // $state.go('login')
                    break;
                default:
                    toastr.info('' + c.head.errorMsg)
            }
        },function(err){
            toastr.info('服务器正忙:'+err)
            $log.debug(err);
        });
      }
  }
})();
